package com.alili_tv.system.service.impl;

import com.alili_tv.system.entity.VideoFavorite;
import com.alili_tv.system.mapper.VideoFavoriteMapper;
import com.alili_tv.system.service.VideoFavoriteService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 收藏的视频 服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2023-03-17
 */
@Service
public class VideoFavoriteServiceImpl extends ServiceImpl<VideoFavoriteMapper, VideoFavorite> implements VideoFavoriteService {

    @Override
    public boolean isCollect(Long id, Long userId) {
        LambdaQueryWrapper<VideoFavorite> queryWrapper = new LambdaQueryWrapper<VideoFavorite>()
                .eq(VideoFavorite::getCreateUser, userId)
                .eq(VideoFavorite::getVideoId, id);
        long count = this.count(queryWrapper);
        return count != 0;
    }

    @Override
    public Long countByVideoId(Long id) {
        LambdaQueryWrapper<VideoFavorite> queryWrapper = new LambdaQueryWrapper<VideoFavorite>()
                .eq(VideoFavorite::getVideoId, id);

        return this.count(queryWrapper);
    }
}
